package dev.ece.core.fog;

import org.lwjgl.opengl.GL20;

import dev.ece.util.lib.Vector3f;
/**
 * 雾化信息
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class Fog {
	
	private static final Fog fog = new Fog();
	
	private boolean enable = true;
	
	private float minDistance = 1f;
	
	private float maxDistance = 5f;
	
	private Vector3f color = new Vector3f(1, 1, 1);
	
	private Fog() {}
	
	public void glUniform(FogLocationHandler handler) {
		GL20.glUniform1i(handler.getEnableHandler(), this.isEnable() ? 1 : 0);
		if(this.isEnable()) {
			GL20.glUniform1f(handler.getMinDistanceHandler(), this.getMinDistance());
			GL20.glUniform1f(handler.getMaxDistanceHandler(), this.getMaxDistance());
			color.glUniform3f(handler.getColorHandler());
		}
	}
	
	public static String getFogStructString() {
		return "struct ece_Fog{\n" +
					"bool enable;\n" +
					"float minDistance;\n" + 
					"float maxDistance;\n" +
					"vec3 color;\n" +
				"};\n";
	}
	
	public static Fog getSysInstance() {
		return fog;
	}
	
	public static Fog newInstance() {
		return new Fog();
	}
	
	public void from(Fog fog) {
		this.enable = fog.enable;
		this.maxDistance = fog.maxDistance;
		this.minDistance = fog.minDistance;
		this.color.set(fog.color);
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public float getMaxDistance() {
		return maxDistance;
	}

	public void setMaxDistance(float maxDistance) {
		this.maxDistance = maxDistance;
	}

	public float getMinDistance() {
		return minDistance;
	}

	public void setMinDistance(float minDistance) {
		this.minDistance = minDistance;
	}

	public Vector3f getColor() {
		return color;
	}
	
}
